package scau.erps.view.freemarket;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import javax.swing.table.AbstractTableModel;

import scau.erps.entity.FreeMarket;

/** 

/**
 * 自由市场表格数据模型
 * @author outsider
 *
 */
public class MarketListModel extends AbstractTableModel {
	private static final long serialVersionUID = 1L;	
		private String[] title = {"序号","卖方小组","产品","数量","价格"};
		private Object[][] data= null;
		private List<FreeMarket> list;
		public MarketListModel(List<FreeMarket> list){	
			this.list=list;
			int i=0;
			Iterator<FreeMarket> iter = list.iterator();
			while(iter.hasNext()) {                       //去除无效条目
				FreeMarket freeMarket = iter.next();
				if(!freeMarket.getType().equals("Research")){
					if (freeMarket.getBuyer()!=0) {
						iter.remove();
						continue;
					}
				}
				
			}	
			data=new Object[list.size()][title.length];
			for (FreeMarket freeMarket:list){
				data[i][0] = freeMarket.getID();
				data[i][1] = freeMarket.getTeamId();
				data[i][2] = freeMarket.getProduct();
				data[i][3] = freeMarket.getNum();
				data[i][4] = freeMarket.getPrice();		
				i++;
			}
	}

	@Override
	public int getRowCount() {
		return this.data.length; //行数
	}

	@Override
	public int getColumnCount() {
		return this.title.length; //列数
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return  data[rowIndex][columnIndex];  //取表格单元格值
	}
	public String getColumnName(int columnIndex) {
        return title[columnIndex];  //显示标题
    }

}
